﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ECommerce.Library.Data
{
    public class Condition
    {
        private string _fieldName;
        private ConditionOperator _conditionalOperator;
        private object _value;
        private JoinOperator _joiningOperator;

        public string FieldName
        {
            get { return this._fieldName; }
            set { this._fieldName = value; }
        }

        public ConditionOperator ConditionalOperator
        {
            get { return this._conditionalOperator; }
            set { this._conditionalOperator = value; }
        }

        public object Value
        {
            get { return this._value; }
            set { this._value = value; }
        }

        public JoinOperator JoiningCondition
        {
            get { return this._joiningOperator; }
            set { this._joiningOperator = value; }
        }

        public Condition() { }

        public Condition(string fieldName, ConditionOperator conditionalOperator, object value, JoinOperator joiningOperator)
        {
            this._fieldName = fieldName;
            this._conditionalOperator = conditionalOperator;
            this._value = value;
            this._joiningOperator = joiningOperator;
        }

        public static string MapCondition(ConditionOperator condition)
        {
            if (condition == ConditionOperator.Equal)
                return " = ";
            else if (condition == ConditionOperator.NotEqual)
                return " <> ";
            else if (condition == ConditionOperator.Greater)
                return " > ";
            else if (condition == ConditionOperator.Less)
                return " < ";
            else if (condition == ConditionOperator.GreaterOrEqual)
                return " >= ";
            else if (condition == ConditionOperator.LessOrEqual)
                return " <= ";
            else if (condition == ConditionOperator.Like)
                return " LIKE ";
            else if (condition == ConditionOperator.NotLike)
                return " NOT LIKE ";
            else
                return string.Empty;
        }
    }

    public enum JoinOperator
    {
        FirstValue = 0,
        And = 1,
        Or = 2
    }

    public enum ConditionOperator
    {       
        Greater = 0,
        Less = 1,
        Equal = 2,
        NotEqual = 3,
        GreaterOrEqual = 4,
        LessOrEqual = 5,
        Like = 6,
        NotLike = 7
    }
}
